package cn.edu.cqvie.ssm.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.Logger;

import cn.edu.cqvie.ssm.entity.User;
import cn.edu.cqvie.ssm.model.UserModel;
import cn.edu.cqvie.ssm.model.impl.UserModelImpl;
import lombok.extern.log4j.Log4j2;

/**
 * Servlet implementation class CheckServlet
 */
@WebServlet("/CheckServlet")
@Log4j2
public class CheckServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public CheckServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		
		String i = (String) request.getParameter("account");
		log.info("account = " + i);
		UserModel um = new UserModelImpl();
		User user =  um.load(new Integer(i));
		log.info("user = " + user);
		PrintWriter out = response.getWriter();
		if(user!=null) {
			out.println(false);
		}else {
			out.println(true);
		}
		out.flush();
		out.close();
	}

}
